package com.aoxin.util.weiXinPay;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import net.sf.json.JSONObject;
//微信h5支付
@XmlAccessorType(XmlAccessType.FIELD)
// XML文件中的根标识
@XmlRootElement(name = "xml")
// 控制JAXB 绑定类中属性和字段的排序
@XmlType(propOrder = { "appid", "mch_id", "notify_url", "trade_type","nonce_str", "sign", "body",
        "out_trade_no", "total_fee","sign_type","attach","scene_info","spbill_create_ip" })
public class WeiXinH5Config implements Serializable {
    private static final long serialVersionUID = 1L;
    public static final String pay_url="https://api.mch.weixin.qq.com/pay/unifiedorder";//支付地址
    public  static String redirect_url="http://pay.sandcubes.com/slf/recharge.html";//h5同步跳转
    //	7jcpBjPsMNHhySGy9yCr6T9oSVU8E2HU
    public static final String key="7jcpBjPsMNHhySGy9yCr6T9oSVU8E2HU";
    private String appid="wx9e4a1955fd462a63";// 公众账号ID
    private String mch_id="1500633451";// 商户号
    private String sign_type="MD5";
    private String attach;
    private String notify_url="http://pay.sandcubes.com/weixinPayNotify/mobileNotify";// 通知地址
//    private String notify_url="http://slf.tunnel.qydev.com/weixinPayNotify/mobileNotify";// 通知地址
    private String trade_type = "MWEB";// 交易类型MWEB h5支付  JSAPI 公众号支付 NATIVE 扫码支付 APP APP支付
    private String spbill_create_ip;// 终端IP
    private String nonce_str;// 随机字符串
    private String sign;// 签名
    private String body;// 商品描述
    private String out_trade_no;// 商户订单号
    private int total_fee;// 总金额(分)
	private String scene_info;// 场景信息
    // {"h5_info": {"type":"Wap","wap_url": "https://pay.qq.com","wap_name":
    // "腾讯充值"}}

    public String getAppId() {
        return appid;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public String getMch_id() {
        return mch_id;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public WeiXinH5Config() {

    }

    public WeiXinH5Config(String body, int total_fee,String attach,String ip) {
        super();
        this.spbill_create_ip = ip;
        this.attach = attach;
        this.nonce_str = getNonce_str();
        this.body = body;
        this.out_trade_no = getOut_trade_no();
        this.total_fee = total_fee;
		this.scene_info = getScene_info();
    }

    public String getNonce_str() {
        nonce_str = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getTrade_type() {
        return trade_type;
    }

    public String getOut_trade_no() {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
        out_trade_no = df.format(new Date());// new Date()为获取当前系统时间
        out_trade_no = out_trade_no + (UUID.randomUUID().toString().trim().replace("-", "").substring(0, 13));
        return out_trade_no;
    }

    public int getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(int total_fee) {
        this.total_fee = total_fee;
    }

    public String getSpbill_create_ip() {
        return spbill_create_ip;
    }

    public void setSpbill_create_ip(String spbill_create_ip) {
        this.spbill_create_ip = spbill_create_ip;
    }

	public String getScene_info() {
		JSONObject jsonObject = new JSONObject();
		JSONObject jsonObject1 = new JSONObject();
		jsonObject1.put("type", "Wap");
		jsonObject1.put("wap_url", "http://www.sandcubes.com");
		jsonObject1.put("wap_name", "腾讯充值");
		jsonObject.put("h5_info", jsonObject1);
		return jsonObject.toString();
	}

    @Override
    public String toString() {
        return "notify_url=" + notify_url ;
    }

//	public String getTonken(){
//		ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>();
//		String token = request.get().getParameter("token");
//		return token;
//	}




    public String getSign_type() {
        return sign_type;
    }

    public void setSign_type(String sign_type) {
        this.sign_type = sign_type;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }
}

